<cfparam name="returnView" type="string" default="workshops" />
<cfparam name="cancelView" type="string" default="#returnView#" />
<cfparam name="listMode" default="radio">
<cfparam name="passback" type="string" default="" />

<cfscript>
	base = new assets.calgrants.com.Base();
	passbackQueryString = base.passbackToQueryString(passback);
	organizationGateway = new assets.calgrants.com.gateway.OrganizationGateway();
	organizations = organizationGateway.query(regionIDs = IIf(IsUserInRole("Regional Admin"), request.authUser.regionID, ""), Organization_ID = IIf(IsUserInRole("Organizer") OR IsUserInRole("Site Contact"), request.authUser.organizationID, ""));
</cfscript>

<cfif organizations.RecordCount gt 0>

	<script type="text/javascript">
		$(function() {
			$("#selectOrganizationModal").modal();
			resizeModal("selectOrganizationModal");	
		})
	</script>

	<cfoutput>
		
		<cfform name="selectOrganizationForm" id="selectOrganizationForm" action="#script_name#" method="post">
			<cfinput type="hidden" name="view" value="#returnView#" />
			<cfif IsDefined("passback")>
				<cfloop index="keyValue" list="#passback#" delimiters=";">
					<cfinput type="hidden" name="#ListFirst(keyValue)#" value="#ListLast(keyValue)#" />
				</cfloop>
			</cfif>
			
			<div id="selectOrganizationModal" class="modal modal-fullscreen" data-backdrop="static">
				<div class="modal-header">
					<h3>Select an organization</h3>
				</div>
				<div class="modal-body">
					<div class="container-fluid">
						<div class="row-fluid">
							<div class="span12">
								<table class="table table-striped table-bordered">
									<thead>
										<tr>
											<cfif listMode eq "radio" OR listMode eq "checkbox">
												<th></th>
											</cfif>
											<th>ID</th>
											<th>Organization</th>
											<cfif IsUserInRole("Super User")>
												<th>Region</th>
											</cfif>
											<th>City</th>
											<th>County</th>
											<th>PA</th>
											<th>OAP</th>
											<th>Users</th>
											<th>Workshops</th>
											<th>Orders</th>
											<th>Status</th>
										</tr>
									</thead>
									<tbody>
										<cfloop query="organizations">
											<tr>
												<cfif listMode eq "radio">
													<td><cfinput type="radio" name="Organization_ID" value="#Organization_ID#"></td>
													<td>#Organization_ID#</td>
												<cfelseif listMode eq "checkbox">
													<td><cfinput type="checkbox" name="Organization_IDs" value="#Organization_ID#"></td>
													<td>#Organization_ID#</td>
												<cfelse>
													<td>#Organization_ID#</td>
												</cfif>
												<td>#Organization#</td>
												<cfif IsUserInRole("Super User")>
													<td>#Region_ID#</td>
												</cfif>
												<td>#City#</td>
												<td>#County#</td>
												<td><cfif pa gt 0>Yes<cfelse><font color="red">No</font></cfif></td>
												<td><cfif oap gt 0>Yes<cfelse><font color="red">No</font></cfif></td>
												<td>#User_Count#</td>
												<td>#Workshop_Count#</td>
												<td>#Order_Count#</td>
												<td>
													<cfif Deleted>
														<font color="red">Deleted</font>
													<cfelseif Archived>
														<font color="silver">Archived</font>
													<cfelseif NOT Approved>
														<font color="orange">Not Approved</font>
													<cfelseif Approved>
														Approved
													</cfif>
												</td>
											</tr>
										</cfloop>
									</tbody>
								</table>		
							</div>
						</div>
					</div>
				</div>
				<div class="modal-footer">
					<a href="?view=#cancelView#" class="btn btn-success">Cancel</a>
					<button type="submit" name="nextButton" class="btn btn-success">Next</button>
				</div>
			</div>
			
		</cfform>
	
	</cfoutput>

<cfelse>

	<div class="alert alert-info notFound">No organizations available for selection</div>
	
</cfif>
	
					